package com.wei.wiki.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/*
 * @author : ShunWei
 * @date : 2022/1/16 11:08
 * @Description: swagger配置类
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket docket(Environment environment) {
        Profiles profiles = Profiles.of("dev", "test");
        boolean flag = environment.acceptsProfiles(profiles);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("shunwei")
                .enable(flag)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.wei.wiki.controller"))
                .build();
    }

    private ApiInfo apiInfo() {
        Contact contact = new Contact("瞬唯", "http://www.shunwei.site", "dobettertang@petalmail.com");
        return new ApiInfo("shun wei Api Document",
                "学无止境",
                "1.0",
                "http://www.shunwei.site",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}